package me.thinkjet.sso.client.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.TimeZone;

public final class CommonUtils {

    private CommonUtils() {
    }

    public static String formatForUtcTime(final Date date) {
	final DateFormat dateFormat = new SimpleDateFormat(
		"yyyy-MM-dd'T'HH:mm:ss'Z'");
	dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
	return dateFormat.format(date);
    }

    public static void assertNotNull(final Object object, final String message) {
	if (object == null) {
	    throw new IllegalArgumentException(message);
	}
    }

    public static void assertNotEmpty(final Collection<?> c,
	    final String message) {
	assertNotNull(c, message);
	if (c.isEmpty()) {
	    throw new IllegalArgumentException(message);
	}
    }

    public static void assertTrue(final boolean cond, final String message) {
	if (!cond) {
	    throw new IllegalArgumentException(message);
	}
    }

    public static boolean isEmpty(final String string) {
	return string == null || string.length() == 0;
    }

    public static boolean isNotEmpty(final String string) {
	return !isEmpty(string);
    }

    public static boolean isBlank(final String string) {
	return isEmpty(string) || string.trim().length() == 0;
    }

    public static boolean isNotBlank(final String string) {
	return !isBlank(string);
    }

}
